
-- stored procedure to a new contact
-- return 1 mean can add, 0 cannot add
IF OBJECT_ID('addContact') IS NOT NULL
BEGIN
	DROP PROCEDURE addContact;
END
GO
CREATE PROCEDURE addContact
	@userId			INT,
	@contactName	VARCHAR(30),
	@contactType	VARCHAR(12)
AS
BEGIN
	IF NOT EXISTS(SELECT * FROM [contact] WHERE contact=@contactName AND contacttype=@contactType)
		BEGIN
			INSERT INTO [contact](userid, contact, contacttype)
			VALUES(@userId, @contactName, @contactType);
			SELECT 1;
		END
	ELSE
		BEGIN
			SELECT 0;
		END
END
GO
